import store from "../store";
import { userInfo } from "../api";
import page from "../router/page";

function auth() {
    userInfo().then((res) => {
        // 把这个权限信息存在本地
        localStorage.setItem("authList", res.data.auth);

        // 把res.data.中的auth 转成数组
        const authList = res.data.auth.split(",");
        const navList = page.filter((item) =>
            authList.some((val) => val === item.meta.auth)
        );
        store.commit("CHANGE_USERINFO", navList);
    });
}

export { auth };